package com.cy.common.util;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import javax.servlet.http.HttpServletRequest;

/**
 * 定义分页操作工具类，在此类方法内部启动分页查询
 */
public class PageUtil {
    public static <T>Page<T> startPage(){
        //获取请求对象
        HttpServletRequest request = ServletUtil.getRequest();

        //获取请求中的分页参数对象
        String pageCurrentStr = request.getParameter("pageCurrent");
        String pageSizeStr = request.getParameter("pageSize");

        Integer pageCurrent = StringUtil.isEmpty(pageCurrentStr)?1:Integer.parseInt(pageCurrentStr);
        Integer pageSize = StringUtil.isEmpty(pageSizeStr)?5:Integer.parseInt(pageSizeStr);

        //启动分页查询
        return PageHelper.startPage(pageCurrent,pageSize);
    }
}
